/*
 * Parser2.h
 *
 *  Created on: Nov 6, 2010
 *      Author: dhovemey
 */

#ifndef PARSER2_H_
#define PARSER2_H_

#include <string>
#include <memory>

class Lexer2;
class ASTNode;

class Parser2 {
private:
	Lexer2 *m_lexer;

	Parser2(const Parser2 &);
	Parser2& operator=(const Parser2 &);

public:
	Parser2(Lexer2 *lexerToAdopt);
	virtual ~Parser2();

	ASTNode *parseTranslationUnit();

private:
	ASTNode *parseTopLevelItem();
	ASTNode *parseImportList();
	ASTNode *parseImport();
	int scanQualifiedClassName(std::wstring &clsName);
	ASTNode *parseStatementList();
	ASTNode *parseStatement();
	ASTNode *parseVariableDeclaration();
	ASTNode *parseVarWithOptInitList();
	ASTNode *parseVarWithOptInit();
	ASTNode *parseClassOrModule();
	ASTNode *parseOptMemberList();
	ASTNode *parseMember();
	ASTNode *parseField();
	static bool checkLegalMethodName(Token2 *token);
	ASTNode *parseMethod();
	ASTNode *parseOptParamList();
	ASTNode *parseOptStatementList();
	ASTNode *parseMagicMethod();
	ASTNode *parseWhileStatement();
	ASTNode *parseIfStatement();
	ASTNode *parseReturnStatement();
	ASTNode *parseExpressionStatement();
	ASTNode *parseExpression();
	ASTNode *parseExpressionWithPrec(ASTNode *lhs, int minPrec);
	ASTNode *parsePrimary();
	int completeMethodCall(
			std::unique_ptr<ASTNode> &primary, std::unique_ptr<ASTNode> &methodCall, const std::wstring &methodName);
	ASTNode *parseLeaf();
	ASTNode *parseArgumentList();
};

#endif /* PARSER2_H_ */
